<template>
  <van-skeleton title avatar :row="5" :loading="state.loading">
    <div class="viewList">
      <!-- topNav -->
      <div class="viewListTop">
        <img class="bgImg" :src="state.playlist.coverImgUrl" alt="" />
        <div class="listViewTopNav">
          <div class="back" @click="$router.go(-1)">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-fanhui"></use>
            </svg>
            <div class="title">歌单</div>
          </div>
          <!-- right -->
          <div class="right">
            <div class="search" @click="$router.push('/search')">
              <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-sousuo"></use>
              </svg>
            </div>
            <div class="config">
              <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-31liebiao"></use>
              </svg>
            </div>
          </div>
        </div>
      </div>
      <!-- 歌单详情 -->
      <div class="content">
        <div class="contentLeft">
          <img :src="state.playlist.coverImgUrl" alt="" />
          <span class="hot">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-huo"></use>
            </svg>
            <span class="mItem_heat">
              {{ `${state.playlist.playCount}万` }}</span
            >
          </span>
        </div>
        <div class="contentRight">
          <h3>{{ state.playlist.name }}</h3>
          <div class="author">
            <img :src="state.playlist.creator.avatarUrl" alt="" />
            <span>{{ state.playlist.creator.nickname }}</span>
          </div>
          <div class="description">
            {{ state.playlist.description }}
          </div>
        </div>
      </div>
      <!-- iconList -->
      <div class="iconList">
        <div class="iconItem">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-liaotian1"></use>
          </svg>
          <span>{{ state.playlist.commentCount }}</span>
        </div>
        <div class="iconItem">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-fenxiang"></use>
          </svg>
          <span>{{ state.playlist.shareCount }}</span>
        </div>
        <div class="iconItem">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-xiazai"></use>
          </svg>
          <span>下载</span>
        </div>
        <div class="iconItem">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-duoxuan"></use>
          </svg>
          <span>多选</span>
        </div>
      </div>
      <!-- 播放列表 -->
      <div class="playList">
        <div class="playListTop">
          <div class="playListTop_left">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-bofang"></use>
            </svg>
            <div class="title">播放全部</div>
            <div class="count">
              {{ `(共${state.playlist.tracks.length}首)` }}
            </div>
          </div>
          <div class="playListTop_right">
            <div class="collect">
              + 收藏({{ state.playlist.subscribedCount }})
            </div>
          </div>
        </div>
        <!-- 歌单list -->
        <div class="musicList">
          <div
            class="musicItem"
            v-for="(item, index) in state.playlist.tracks"
            :key="index"
          >
            <div class="left" @click="playMusic(index, item)">
              <div class="index">{{ index + 1 }}</div>
              <div class="content">
                <div class="title">{{ item.name }}</div>
                <div class="author">
                  <span
                    class="tag"
                    v-for="(tag, index2) in state.playlist.tags"
                    :key="index2"
                    >{{ tag }}</span
                  >{{ item.al.name }}
                </div>
              </div>
            </div>
            <div class="right">
              <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-bofang1"></use>
              </svg>
              <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-31liebiao"></use>
              </svg>
            </div>
          </div>
        </div>
      </div>
    </div>
  </van-skeleton>
</template>

<script>
import ViewListTop from '@/components/ViewListTop.vue'
import { onMounted, reactive, getCurrentInstance, ref } from 'vue'
import { useRoute } from 'vue-router'
import { useStore } from 'vuex'
export default {
  name: 'ViewList',
  components: {
    ViewListTop,
  },
  setup() {
    const { proxy } = getCurrentInstance()
    const router = useRoute()
    const store = useStore()
    let state = reactive({
      list: [],
      playlist: {
        creator: {},
        tracks: [],
      },
      loading: true,
    })
    onMounted(() => {
      proxy.$axios
        .get(`http://localhost:3000/playlist/detail?id=${router.query.id}`)
        .then((res) => {
          console.log(2222, res.data)
          let { playlist } = res.data
          state.playlist = playlist
          console.log(playlist.tracks)
          // 存入vuex
          store.commit('setPlayList', state.playlist.tracks)
          state.loading = false
        })
    })
    let playMusic = (index, item) => {
      console.log(index, item)
      store.commit('setCurrentIndex', index);
    }
    return {
      state,
      playMusic,
      router,
    }
  },
}
</script>
<style lang="less" scoped>
.viewList {
  .viewListTop {
    color: #fff;
    height: 1.2rem;
    .bgImg {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: auto;
      z-index: -1;
      filter: blur(25px);
    }
    .listViewTopNav {
      padding: 0.4rem 0.3rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .back {
        display: flex;
        .icon {
          width: 0.5rem;
          height: 0.5rem;
        }
        .title {
          margin-left: 0.3rem;
          font-size: 0.4rem;
          text-align: center;
          line-height: 0.6rem;
        }
      }
      .right {
        .icon {
          width: 0.5rem;
          height: 0.5rem;
        }
        display: flex;
        .search {
          margin-right: 0.5rem;
          .icon {
            width: 0.6rem;
            height: 0.6rem;
            color: #fff !important;
          }
        }
      }
    }
  }
  // content
  .content {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0.4rem;
    .contentLeft {
      position: relative;
      margin-right: 0.3rem;
      img {
        width: 2.6rem;
        height: 2.6rem;
        border-radius: 0.1rem;
      }
      .hot {
        position: absolute;
        top: 0.1rem;
        right: 0.1rem;
        color: red;
        .icon {
          position: absolute;
          top: -2px;
          left: -15px;
        }
      }
    }
    // 右侧
    .contentRight {
      h3 {
        color: #fff;
        font-size: 0.35rem;
        font-weight: 700;
        line-height: 0.5rem;
      }
      .author {
        display: flex;
        align-items: center;
        margin: 0.2rem 0;
        img {
          width: 0.6rem;
          height: 0.6rem;
          border-radius: 0.3rem;
          margin-right: 0.2rem;
        }
        span {
          color: #ccc;
          font-size: 0.24rem;
        }
      }
      .description {
        font-size: 0.24rem;
        color: #ccc;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
    }
  }
  // iconList
  .iconList {
    display: flex;
    justify-content: space-around;
    .iconItem {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .icon {
        width: 0.6rem;
        height: 0.6rem;
        fill: #fff;
        margin-bottom: 0.2rem;
      }
      span {
        color: #ccc;
      }
    }
  }
  // playList
  .playList {
    margin-top: 0.5rem;
    background-color: #fff;
    border-radius: 0.4rem 0.4rem 0 0;
    .playListTop {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 0.8rem;
      padding: 0.3rem;
      line-height: 0.8rem;
      .playListTop_left {
        display: flex;
        .icon {
          width: 0.5rem;
          height: 0.5rem;
          fill: #000;
          margin-top: 0.1rem;
          margin-right: 0.2rem;
        }
        .title {
          color: #000;
          font-size: 0.35rem;
          margin-right: 0.2rem;
        }
        .count {
          color: #ccc;
          font-size: 0.2rem;
        }
      }
      .playListTop_right {
        // flex: 1;
        .collect {
          width: 2.5rem;
          height: 1rem;
          background-color: rgb(254, 57, 60);
          border-radius: 0.5rem;
          line-height: 1rem;
          color: #fff;
          text-align: center;
          font-size: 0.25rem;
        }
      }
    }
  }
  // musicList
  .musicList {
    .musicItem {
      display: flex;
      align-items: center;
      padding: 0 0.3rem;
      .left {
        flex: 8;
        position: relative;
        .index {
          width: 0.5rem;
          color: #ccc;
          position: absolute;
          top: 50%;
          left: 0;
          transform: translate(0, -50%);
        }
        .content {
          margin-left: 0.2rem;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          padding: 0.3rem;
          .title {
            font-size: 0.3rem;
            color: #000;
            font-weight: 600;
            padding-bottom: 0.2rem;
          }
          .author {
            color: #ccc;
            font-size: 0.2rem;
            height: 0.4rem;
            line-height: 0.4rem;
          }
          .tag {
            font-size: 0.1rem;
            color: orangered;
            border: 1px solid orangered;
            border-radius: 0.05rem;
            &:last-child {
              margin-right: 0.1rem;
            }
          }
        }
      }
      .right {
        flex: 2;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .icon {
          width: 0.5rem;
          height: 0.5rem;
          fill: #ccc;
        }
      }
    }
  }
}
</style>
